Array.prototype.toggle = function (obj, prop) {
  let index, flag = false

  if (prop) {
    for (let i = 0, length = this.length; i < length; i++) {
      if (obj[prop] === this[i][prop]) {
        index = i
        flag = true
        break
      }
    }
  } else {
    for (let i = 0, length = this.length; i < length; i++) {
      if (obj === this[i]) {
        index = i
        flag = true
        break
      }
    }
  }

  if (flag) {
    this.splice(index, 1)
  } else {
    this.push(obj)
  }
}

Array.prototype.remove = function (obj, prop) {
  let index, flag = false

  if (prop) {
    for (let i = 0, length = this.length; i < length; i++) {
      if (obj[prop] === this[i][prop]) {
        index = i
        flag = true
        break
      }
    }
  } else {
    for (let i = 0, length = this.length; i < length; i++) {
      if (obj === this[i]) {
        index = i
        flag = true
        break
      }
    }
  }

  if (flag) {
    this.splice(index, 1)
  }
}
